package io.github.xbeeant.eoffice.config;

import io.github.xbeeant.core.ApiResponse;
import io.github.xbeeant.http.Requests;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletResponse;

/**
 * @author xiaobiao
 * @version 2021/7/8
 */
@ControllerAdvice
public class GlobalExceptionHandler {
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);


    @ExceptionHandler(Exception.class)
    public void clientAbortExceptionHandler(Exception e, HttpServletResponse response) {
        ApiResponse<String> msg = new ApiResponse<>(500, "系统异常");

        logger.error("异常", e);
        Requests.writeJson(response, msg);
    }
}
